﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL;

namespace QuanLyPhongTroDevLinQ
{
    public partial class Frm_TimPhieuThu : Form
    {
        int TimKiem;
        public static List<DanhSachPhieuThuResult> timkiemPhieuThu;
        QuanLyPhongTroDBDataContext dbs;
        public Frm_TimPhieuThu(int timKiem)
        {
            InitializeComponent();
            TimKiem = timKiem;
            dbs = new QuanLyPhongTroDBDataContext();
            

        }

        private void Frm_TimPhieuThu_Load(object sender, EventArgs e)
        {
            txtTimKiem.Focus();
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {

            switch (TimKiem)
            {
                case 0:
                    try 
                    {
                        var timkiem = from pt in dbs.DanhSachPhieuThu()
                                      where pt.NgayThu.Month== int.Parse(txtTimKiem.Text)
                                      select pt;
                        timkiemPhieuThu = timkiem.ToList();
                    }
                    catch (Exception)
                    {
                        txtTimKiem.Reset();
                        MessageBox.Show("Giá trị nhập không hợp lệ!");
                        txtTimKiem.Focus();
                    }



                    break;
                case 1:
                    try
                    {
                        var timkiem = from pt in dbs.DanhSachPhieuThu()
                                      where pt.MaHoaDon.Contains(txtTimKiem.Text.Trim())
                                      select pt;
                        timkiemPhieuThu = timkiem.ToList();
                    }
                    catch (Exception)
                    {
                        txtTimKiem.Reset();
                        MessageBox.Show("Giá trị nhập không hợp lệ!");
                        txtTimKiem.Focus();
                    }
                    break;
                case 2:
                    try
                    {
                        var timkiem = from pt in dbs.DanhSachPhieuThu()
                                      where pt.MaPhieuThu.Contains(txtTimKiem.Text.Trim())
                                      select pt;
                        timkiemPhieuThu = timkiem.ToList();
                    }
                    catch (Exception)
                    {
                        txtTimKiem.Reset();
                        MessageBox.Show("Giá trị nhập không hợp lệ!");
                        txtTimKiem.Focus();
                    }
                    break;

            }
        }
    }
}
